home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\FUNNY.C < prev    next >
C/C++ Source or Header  |  1995-01-03  |  9KB  |  431 lines

  1. /*
  2.  * funny.c: Well, I put some stuff here and called it funny.  So sue me. 
  3.  *
  4.  * written by michael sandrof
  5.  *
  6.  * copyright(c) 1990 
  7.  *
  8.  * see the copyright file, or do a help ircii copyright 
  9.  */
  10.  
  11. #ifndef lint
  12. static    char    rcsid[] = "@(#)$Id: funny.c,v 1.9 1994/07/02 02:32:13 mrg Stab $";
  13. #endif
  14.  
  15. #include "irc.h"
  16.  
  17. #include "ircaux.h"
  18. #include "hook.h"
  19. #include "vars.h"
  20. #include "funny.h"
  21. #include "names.h"
  22. #include "server.h"
  23. #include "lastlog.h"
  24. #include "term.h"
  25. #include "output.h"
  26. #include "numbers.h"
  27. #include "parse.h"
  28. #include "window.h"
  29. #include "screen.h"
  30.  
  31. static    char    *names_channel = (char *) 0;
  32. static    char    *mode_channel = (char *) 0;
  33. static    char    *match = (char *) 0;
  34. static    int    ignore_mode = 0;
  35.  
  36. static    int    funny_min;
  37. static    int    funny_max;
  38. static    int    funny_flags;
  39.  
  40. int funny_is_ignore_channel()
  41. {
  42.     return (names_channel != (char *) 0);
  43. }
  44.  
  45. void    funny_match(stuff)
  46. char    *stuff;
  47. {
  48.     malloc_strcpy(&match, stuff);
  49. }
  50.  
  51. void    funny_set_ignore_mode()
  52. {
  53.     mode_channel = names_channel;
  54.     names_channel = (char *) 0;
  55.     ignore_mode++;
  56. }
  57.  
  58. void    funny_set_ignore_channel(str)
  59. char    *str;
  60. {
  61.     malloc_strcpy(&names_channel, str);
  62. }
  63.  
  64. void    set_funny_flags(min, max, flags)
  65. int    min,
  66.     max,
  67.     flags;
  68. {
  69.     funny_min = min;
  70.     funny_max = max;
  71.     funny_flags = flags;
  72. }
  73.  
  74. struct    WideListInfoStru
  75. {
  76.     char    *channel;
  77.     int    users;
  78. };
  79.  
  80. typedef    struct WideListInfoStru WideList;
  81.  
  82. static    WideList **wide_list = (WideList **) 0;
  83. static    int    wl_size = 0;
  84. static    int    wl_elements = 0;
  85.  
  86. int    funny_widelist_users(left, right)
  87. WideList    **left,
  88.         **right;
  89. {
  90.     if ((**left).users > (**right).users)
  91.         return -1;
  92.     else if ((**right).users > (**left).users)
  93.         return 1;
  94.     else
  95.         return my_stricmp((**left).channel, (**right).channel);
  96. }
  97.  
  98. int    funny_widelist_names(left, right)
  99. WideList    **left,
  100.         **right;
  101. {
  102.     int    comp;
  103.  
  104.     if ((comp = my_stricmp((**left).channel, (**right).channel)) != 0)
  105.         return comp;
  106.     else if ((**left).users > (**right).users)
  107.         return -1;
  108.     else if ((**right).users > (**left).users)
  109.         return 1;
  110.     else
  111.         return 0;
  112. }
  113.  
  114.  
  115. void    funny_print_widelist()
  116. {
  117.     int    i;
  118.     define_big_buffer(buffer1);
  119.     define_big_buffer(buffer2);
  120.     char    *ptr;
  121.     Screen    *old_current_screen;
  122.     Window    *output_window;
  123.  
  124.     if (!wide_list)
  125.     {
  126.         free_big_buffer(buffer1);
  127.         free_big_buffer(buffer2);
  128.         return;
  129.     }
  130.  
  131.     if (funny_flags & FUNNY_NAME)
  132.         qsort((void *) wide_list, wl_elements, sizeof(WideList *),
  133.         funny_widelist_names);
  134.     else if (funny_flags & FUNNY_USERS)
  135.         qsort((void *) wide_list, wl_elements, sizeof(WideList *),
  136.         funny_widelist_users);
  137.  
  138.     old_current_screen = current_screen;
  139.     output_window = get_output_window();
  140.     set_win_scr(output_window);
  141.  
  142.     *buffer1 = '\0';
  143.     for (i = 0; i < wl_elements; i++)
  144.     {
  145.         sprintf(buffer2, "%s(%d) ", wide_list[i]->channel,
  146.                 wide_list[i]->users);
  147.         ptr = index(buffer1, '\0');
  148.         if (strlen(buffer1) + strlen(buffer2) > CO - 5)
  149.         {
  150.             if (do_hook(WIDELIST_LIST, "%s", buffer1))
  151.                 say("%s", buffer1);
  152.             *buffer1 = '\0';
  153.             strcat(buffer1, buffer2);
  154.         }
  155.         else
  156.             strcpy(ptr, buffer2);
  157.     }
  158.     if (*buffer1 && do_hook(WIDELIST_LIST, "%s", buffer1))
  159.         say("%s" , buffer1);
  160.     for (i = 0; i < wl_elements; i++)
  161.     {
  162.         new_free(&wide_list[i]->channel);
  163.         new_free(&wide_list[i]);
  164.     }
  165.     new_free(&wide_list);
  166.     set_current_screen(old_current_screen);
  167.     wl_elements = wl_size = 0;
  168.     free_big_buffer(buffer1);
  169.     free_big_buffer(buffer2);
  170. }
  171.  
  172. /*ARGSUSED*/
  173. void    funny_list(from, ArgList)
  174. char    *from;
  175. char    **ArgList;
  176. {
  177.     char    *channel,
  178.         *user_cnt,
  179.         *line;
  180.     WideList **new_list;
  181.     int    cnt;
  182.     static    char    format[25];
  183.     static    unsigned int    last_width = -1;
  184.  
  185.     if (last_width != get_int_var(CHANNEL_NAME_WIDTH_VAR))
  186.     {
  187.         if ((last_width = get_int_var(CHANNEL_NAME_WIDTH_VAR)) != 0)
  188.             sprintf(format, "*** %%-%u.%us %%-5s  %%s",
  189.                 (unsigned char) last_width,
  190.                 (unsigned char) last_width);
  191.         else
  192.             strcpy(format, "*** %s\t%-5s  %s");
  193.     }
  194.     channel = ArgList[0];
  195.     user_cnt = ArgList[1];
  196.     line = PasteArgs(ArgList, 2);
  197.     if (funny_flags & FUNNY_TOPIC && !(line && *line))
  198.             return;
  199.     cnt = atoi(user_cnt);
  200.     if (funny_min && (cnt < funny_min))
  201.         return;
  202.     if (funny_max && (cnt > funny_max))
  203.         return;
  204.     if ((funny_flags & FUNNY_PRIVATE) && (*channel != '*'))
  205.         return;
  206.     if ((funny_flags & FUNNY_PUBLIC) && (*channel == '*'))
  207.         return;
  208.     if (match)
  209.     {
  210.         if (wild_match(match, channel) == 0)
  211.             return;
  212.     }
  213.     if (funny_flags & FUNNY_WIDE)
  214.     {
  215.         if (wl_elements >= wl_size)
  216.         {
  217.             new_list = (WideList **) new_malloc(sizeof(WideList *) *
  218.                 (wl_size + 50));
  219.             bzero(new_list, sizeof(WideList *) * (wl_size + 50));
  220.             if (wl_size)
  221.                 bcopy(wide_list, new_list, sizeof(WideList *)
  222.                     * wl_size);
  223.             wl_size += 50;
  224.             new_free(&wide_list);
  225.             wide_list = new_list;
  226.         }
  227.         wide_list[wl_elements] = (WideList *)
  228.             new_malloc(sizeof(WideList));
  229.         wide_list[wl_elements]->channel = (char *) 0;
  230.         wide_list[wl_elements]->users = cnt;
  231.         malloc_strcpy(&wide_list[wl_elements]->channel,
  232.                 (*channel != '*') ? channel : "Prv");
  233.         wl_elements++;
  234.         return;
  235.     }
  236.     if (do_hook(current_numeric, "%s %s %s %s", from,  channel, user_cnt,
  237.         line) && do_hook(LIST_LIST, "%s %s %s", channel, user_cnt, line))
  238.     {
  239.         if (channel && user_cnt)
  240.         {
  241.             if (*channel == '*')
  242.                 put_it(format, "Prv", user_cnt, line);
  243.             else
  244.                 put_it(format, channel, user_cnt, line);
  245.         }
  246.     }
  247. }
  248.  
  249. void    funny_namreply(from, Args)
  250. char    *from;
  251. char    **Args;
  252. {
  253.     char    *type,
  254.         *nick,
  255.         *channel;
  256.     static    char    format[40];
  257.     static    unsigned int    last_width = -1;
  258.     int    cnt;
  259.     char    *ptr;
  260.     char    *line;
  261.  
  262.     PasteArgs(Args, 2);
  263.     type = Args[0];
  264.     channel = Args[1];
  265.     line = Args[2];
  266.     message_from(channel, LOG_CRAP);
  267.     if (names_channel && !my_stricmp(names_channel, channel))
  268.     {
  269.         if (do_hook(current_numeric, "%s %s %s %s", from, type, channel,
  270.             line) && get_int_var(SHOW_CHANNEL_NAMES_VAR))
  271.             say("Users on %s: %s", channel, line);
  272.         while ((nick = next_arg(line, &line)) != NULL)
  273.             add_to_channel(channel, nick, from_server);
  274.         message_from(NULL, LOG_CURRENT);
  275.         return;
  276.     }
  277.     if (last_width != get_int_var(CHANNEL_NAME_WIDTH_VAR))
  278.     {
  279.         if ((last_width = get_int_var(CHANNEL_NAME_WIDTH_VAR)) != 0)
  280.             sprintf(format, "%%s: %%-%u.%us %%s",
  281.                 (unsigned char) last_width,
  282.                 (unsigned char) last_width);
  283.         else
  284.             strcpy(format, "%s: %s\t%s");
  285.     }
  286.     ptr = line;
  287.     for (cnt = -1; ptr; cnt++)
  288.     {
  289.         if ((ptr = index(ptr, ' ')) != NULL)
  290.             ptr++;
  291.     }
  292.     if (funny_min && (cnt < funny_min))
  293.         return;
  294.     else if (funny_max && (cnt > funny_max))
  295.         return;
  296.     if ((funny_flags & FUNNY_PRIVATE) && (*type == '='))
  297.         return;
  298.     if ((funny_flags & FUNNY_PUBLIC) && (*type == '*'))
  299.         return;
  300.     if (type && channel)
  301.     {
  302.         if (match)
  303.         {
  304.             if (wild_match(match, channel) == 0)
  305.                 return;
  306.         }
  307.         if (do_hook(current_numeric, "%s %s %s %s", from, type, channel,
  308.             line) && do_hook(NAMES_LIST, "%s %s", channel, line))
  309.         {
  310.             switch (*type)
  311.             {
  312.             case '=':
  313.                 if (last_width &&(strlen(channel) > last_width))
  314.                 {
  315.                     channel[last_width-1] = '>';
  316.                     channel[last_width] = (char) 0;
  317.                 }
  318.                 put_it(format, "Pub", channel, line);
  319.                 break;
  320.             case '*':
  321.                 put_it(format, "Prv", channel, line);
  322.                 break;
  323.             case '@':
  324.                 put_it(format, "Sec", channel, line);
  325.                 break;
  326.             }
  327.         }
  328.     }
  329.     message_from(NULL, LOG_CURRENT);
  330. }
  331.  
  332. void    funny_mode(from, ArgList)
  333. char    *from,
  334.     **ArgList;
  335. {
  336.     char    *mode, *channel;
  337.  
  338.     if (!ArgList[0]) return;
  339.     if (get_server_version(from_server)<Server2_6)
  340.     {
  341.         channel = (char *) 0;
  342.         mode = ArgList[0];
  343.         PasteArgs(ArgList, 0);
  344.     }
  345.     else
  346.     {
  347.         channel = ArgList[0];
  348.         mode = ArgList[1];
  349.         PasteArgs(ArgList, 1);
  350.     }
  351.     if (ignore_mode)
  352.     {
  353.         update_channel_mode(channel ? channel : mode_channel, mode);
  354.         update_all_status();
  355.         ignore_mode--;
  356.         new_free(&mode_channel);
  357.     }
  358.     else
  359.     {
  360.         if (channel)
  361.         {
  362.             message_from(channel, LOG_CRAP);
  363.             if (do_hook(current_numeric, "%s %s %s", from,
  364.                     channel, mode))
  365.                 put_it("%s Mode for channel %s is \"%s\"",
  366.                     numeric_banner(), channel, mode);
  367.         }
  368.         else
  369.         {
  370.             if (do_hook(current_numeric, "%s %s", from, mode))
  371.                 put_it("%s Channel mode is \"%s\"",
  372.                     numeric_banner(), mode);
  373.         }
  374.     }
  375. }
  376.  
  377. void    update_user_mode(modes)
  378. char    *modes;
  379. {
  380.     int    onoff = 1;
  381.  
  382.     while (*modes)
  383.     {
  384.         switch(*modes++)
  385.         {
  386.         case '-':
  387.             onoff=0;
  388.             break;
  389.         case '+':
  390.             onoff=1;
  391.             break;
  392.         case 'o':
  393.         case 'O':
  394.             set_server_operator(from_server, onoff);
  395.             break;
  396.         case 's':
  397.         case 'S':
  398.             set_server_flag(from_server, USER_MODE_S, onoff);
  399.             break;
  400.         case 'i':
  401.         case 'I':
  402.             set_server_flag(from_server, USER_MODE_I, onoff);
  403.             break;
  404.         case 'w':
  405.         case 'W':
  406.             set_server_flag(from_server, USER_MODE_W, onoff);
  407.             break;
  408.         }
  409.     }
  410. }
  411.  
  412. void    reinstate_user_modes()
  413. {
  414.     char    modes[10];
  415.     char    *c;
  416.  
  417.     if (get_server_version(from_server) < Server2_7)
  418.         return;
  419.     c = modes;
  420.     if (get_server_flag(from_server, USER_MODE_W))
  421.         *c++ = 'w';
  422.     if (get_server_flag(from_server, USER_MODE_S))
  423.         *c++ = 's';
  424.     if (get_server_flag(from_server, USER_MODE_I))
  425.         *c++ = 'i';
  426.     *c = '\0';
  427.     if (c != modes)
  428.         send_to_server("MODE %s +%s", get_server_nickname(from_server),
  429.         modes);
  430. }
  431.